<%@page import="shop.vo.ProductBean"%>
<%@page import="shop.vo.UserBean"%>
<%@page import="java.util.Iterator"%>
<%@page import="shop.vo.CommentBean"%>
<%@page import="java.util.List"%>
<%@page import="shop.factory.DAOFactory"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="../css/bootstrap.min.css">
<script src="../js/jquery-1.10.2.min.js" type="text/javascript"
	charset="utf-8"></script>
<script type="text/javascript" src="../js/bootstrap.min.js"></script>
<title></title>
<style type="text/css">

th,td{
		text-align: center;
	}
</style>
</head>
<%
	if (!(boolean)session.getAttribute("adminLogin")) {
		String path = request.getContextPath() + "/Admin/login.jsp";
		response.sendRedirect(path);
	}
%>
<body>
	<div class="container-fluid">
		<h3>评论管理</h3>
		<div class="page-header" style="margin-top: 10px;"></div>
		<form action="<%=request.getContextPath() %>/CommentServlet" method="post">
		<input type="hidden" name="action" value="commentdelete">
			<table class="table table-bordered table-condensed table-striped">
				<tr>
					<th>多选</th>
					<th>序号</th>
					<th>评论内容</th>
					<th>评论时间</th>
					<th>评论分数</th>
					<th>评论人</th>
					<th>评论商品</th>
				</tr>
				<%
					int nowPage = 1;
							int pageSize = 10;
							String str = request.getParameter("to");
							if (str != null) {
								nowPage = Integer.parseInt(str);
							}
							int up = nowPage;
							int next = nowPage;
							int maxPage = 0;
							int count = DAOFactory.getICommentDAOInstance().getCount();
							if (count % pageSize == 0) {
								maxPage = count / pageSize;
							} else {
								maxPage = (count / pageSize) + 1;
							}
							if (next < maxPage) {
								next += 1;
							}
							if (up > 1) {
								up -= 1;
							}
							List<CommentBean> list = DAOFactory.getICommentDAOInstance().list(nowPage, pageSize);
							Iterator<CommentBean> it = list.iterator();
							while (it.hasNext()) {
								CommentBean com = it.next();
								UserBean user = com.getUser();
								ProductBean product = com.getProduct();
				%>
				<tr>
					<td><input type="checkbox"
						value="<%=com.getCom_id()%>" id="cheboxId" name="cheboxId"></td>
					<td><%=com.getCom_id()%></td>
					<td><%=com.getCom_content()%></td>
					<td><%=com.getCom_time()%></td>
					<td><%=com.getCom_score()%></td>
					<td><%=user.getUser_name()%></td>
					<td><%=product.getPro_name()%></td>
				</tr>
				<%
					}
				%>
				<tr>
					<td align="center" colspan="12"><input type="button"
						value="全选" onclick="quan()">&nbsp;&nbsp;&nbsp;&nbsp;<input
						type="button" value="反选" onclick="fan()">&nbsp;&nbsp;&nbsp;&nbsp;<input
						type="reset" value="重置">&nbsp;&nbsp;&nbsp;&nbsp;<input
						type="submit" value="删除"></td>
				</tr>
				<tr>
					<td colspan="12" align="center"><span class="style1"> <a
							href="userList.jsp?to=1">首页</a>&nbsp;|&nbsp; <a
							href="userList.jsp?to=<%=up%>">上一页</a>&nbsp;|&nbsp;<a
							href="userList.jsp?to=<%=next%>">下一页</a>&nbsp;|&nbsp; <a
							href="userList.jsp?to=<%=maxPage%>">尾页</a>
					</span> &nbsp;&nbsp;第&nbsp;<%=nowPage%>&nbsp;页/共&nbsp;<%=maxPage%>&nbsp;页</td>
				</tr>
			</table>
		</form>
	</div>
</body>
<script type="text/javascript">
	function quan() {
		var checkObj = document.all("cheboxId");
		for (var i = 0; i < checkObj.length; i++) {
			checkObj[i].checked = true;
		}
	}
	function fan() {
		var checkObj = document.all("cheboxId");
		for (var i = 0; i < checkObj.length; i++) {
			if (checkObj[i].checked == true)
				checkObj[i].checked = false;
			else
				checkObj[i].checked = true;
		}
	}
</script>
</html>